package com.zhouyibike.uu.ui.adapter;


import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.widget.TextViewCompat;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.LvMenuItem;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 暂未使用  过时
 */
@Deprecated
public class MenuItemAdapter extends BaseAdapter
{
    private final int mIconSize;
    private LayoutInflater mInflater;
    private Context mContext;

    public MenuItemAdapter(Context context)
    {
        mInflater = LayoutInflater.from(context);
        mContext = context;

        mIconSize = context.getResources().getDimensionPixelSize(R.dimen.drawer_icon_size);
    }

    private List<LvMenuItem> mItems = new ArrayList<LvMenuItem>(
            Arrays.asList(
                    new LvMenuItem(R.mipmap.xingcheng_left, "我的行程"),
                    new LvMenuItem(R.mipmap.qianbao_left, "我的钱包"),
                    new LvMenuItem(R.mipmap.danche_left, "我的单车"),
                    new LvMenuItem(R.mipmap.yaoqing_left, "邀请分享"),
                    new LvMenuItem(R.mipmap.paiming_left, "骑车排名"),
                    new LvMenuItem(R.mipmap.zhinan_left, "使用指南"),
                    new LvMenuItem(R.mipmap.jvbao_left, "我要举报")
            ));


    @Override
    public int getCount()
    {
        return mItems.size();
    }


    @Override
    public Object getItem(int position)
    {
        return mItems.get(position);
    }


    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public int getViewTypeCount()
    {
        return 3;
    }

//    @Override
//    public int getItemViewType(int position)
//    {
//        return mItems.get(position-1).getType();
//    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        LvMenuItem item = mItems.get(position);
        switch (item.getType())
        {
            case LvMenuItem.TYPE_NORMAL:
                if (convertView == null)
                {
                    convertView = mInflater.inflate(R.layout.design_drawer_item, parent,
                            false);
                }
                TextView itemView = (TextView) convertView;
                itemView.setText(item.getName());
                Drawable icon = mContext.getResources().getDrawable(item.getIcon());
                setIconColor(icon);
                if (icon != null)
                {
                    icon.setBounds(0, 0, mIconSize, mIconSize);
                    TextViewCompat.setCompoundDrawablesRelative(itemView, icon, null, null, null);
                }

                break;

        }

        return convertView;
    }

    public void setIconColor(Drawable icon)
    {
        int textColorSecondary = R.color.colorPrimary;
        TypedValue value = new TypedValue();
        if (!mContext.getTheme().resolveAttribute(textColorSecondary, value, true))
        {
            return;
        }
        int baseColor = mContext.getResources().getColor(value.resourceId);
        icon.setColorFilter(baseColor, PorterDuff.Mode.MULTIPLY);
    }
    public void setViewChange(){

    }
}
